package com.samebuilding.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.math.NumberUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.samebuilding.domain.Activity;
import com.samebuilding.domain.ActivityBigtype;
import com.samebuilding.domain.ActivityMember;
import com.samebuilding.domain.Comment;
import com.samebuilding.domain.User;
import com.samebuilding.service.ActivityService;
import com.samebuilding.service.ActivityTypeService;
import com.samebuilding.service.CommentService;
import com.samebuilding.util.WebUtil;

public class GetActivityAction extends Action {

	
	private ActivityService activityService;
	private ActivityTypeService activityTypeService;
	private CommentService commentService;
	
	
	
	
	public CommentService getCommentService() {
		return commentService;
	}





	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}





	public ActivityTypeService getActivityTypeService() {
		return activityTypeService;
	}





	public void setActivityTypeService(ActivityTypeService activityTypeService) {
		this.activityTypeService = activityTypeService;
	}





	public ActivityService getActivityService() {
		return activityService;
	}





	public void setActivityService(ActivityService activityService) {
		this.activityService = activityService;
	}





	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		User user = (User)request.getSession().getAttribute("user");
		
		List<ActivityBigtype> list = this.activityTypeService.findAllBigType();
		
		
		
		int activityId = NumberUtils.createInteger(request.getParameter("activityId"));
		
		Activity activity = this.activityService.getActivity(activityId);
		boolean  isJoin = this.activityService.hasJoinActivity(activityId, user.getUserNo());
		
		int memberCount = this.activityService.findCountActivityMemberByActivityId(activityId);
		List<ActivityMember> memberList = this.activityService.findActivityMemberByActivityId(activityId, 0, 6);
		
		int commentCount = this.commentService.getCountCommentByType(activityId, CommentAction.ACTIVITY);
		List<Comment> commentList = this.commentService.getCommentByType(activityId, CommentAction.ACTIVITY, 0, 10);
		
		
		request.setAttribute("memberList", memberList);
		request.setAttribute("memberCount", memberCount);
		request.setAttribute("list", list);
		request.setAttribute("activity", activity);
		request.setAttribute("isJoin", isJoin);
		request.setAttribute("commentCount", commentCount);
		request.setAttribute("commentList", commentList);
		
		return mapping.findForward("getActivity");
	}

	
	
	
	
}
